#include <iostream>
using namespace std;


struct ListNode {
	int val;
	struct ListNode *next;
	ListNode(int x) :
		val(x), next(NULL) {
	}
};

void rever(ListNode* first, ListNode* last)
{
	if (first->next == last)
	{
		ListNode* tmp = first;
		first = last;
		last = tmp;
		first->next = first;
		last->next = NULL;
		return;
	}
	else
	{
		ListNode* head = first;
		first = first->next;
		rever(first, last);
		last->next = head;
		head->next = NULL;
		last = last->next;
	}
}

ListNode* ReverseList(ListNode* pHead) {
	if (pHead == NULL) return NULL;
	if (pHead->next == NULL) return pHead;
	ListNode* left = NULL;
	ListNode* newHead = pHead;
	pHead = pHead->next;
	newHead->next = left;
	while (pHead != NULL)
	{
		left = newHead;
		newHead = pHead;
		pHead = pHead->next;
		newHead->next = left;
	}
	pHead = newHead;

	while (newHead != NULL)
	{
		cout << newHead->val << endl;
		newHead = newHead->next;
	}

	return pHead;
}



//int main()
//{
//	ListNode* head = new ListNode(1);
//	ListNode* p1 = head;
//	for (int i = 2; i < 10; ++i)
//	{
//		ListNode* p = new ListNode(i);
//		p1->next = p;
//		p1 = p1->next;
//
//	}
//
//	ReverseList(head);
//
//	system("pause");
//	return 0;
//}